package com.example.moments.db;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;

import com.example.moments.dao.CommentDao;
import com.example.moments.dao.ContentDao;
import com.example.moments.dao.ImageDao;
import com.example.moments.dao.LikeDao;
import com.example.moments.dao.LinkDao;
import com.example.moments.ssmemo.entity.Comment;
import com.example.moments.ssmemo.entity.Content;
import com.example.moments.ssmemo.entity.Image;
import com.example.moments.ssmemo.entity.Like;
import com.example.moments.ssmemo.entity.Link;

//import en.edu.zucc.pb.loginapplication.dao.RecordDao;
//import en.edu.zucc.pb.loginapplication.dao.UserDao;
//import en.edu.zucc.pb.loginapplication.entity.Record;
//import en.edu.zucc.pb.loginapplication.entity.User;

//import en.edu.zucc.pb.room.dao.AuthorDao;
//import en.edu.zucc.pb.room.dao.BookDao;
//import en.edu.zucc.pb.room.entity.Author;
//import en.edu.zucc.pb.room.entity.Book;

//1
@Database(entities = {Comment.class, Content.class,
        Image.class, Like.class, Link.class}, version = 2, exportSchema = false)
@TypeConverters({RoomConverter.class})
public abstract class AppDatabase extends RoomDatabase {
    //    public abstract AuthorDao authorDao();
    private static final String DATABASE_NAME = "";
    private static final String DATABASE_FILENAME = "moments.db";
//    public abstract UserDao userDao();
//    确实 这会 生成代码
//    public abstract BookDao bookDao();

    /**
     * 获取AlarmClockDao对象
     *
     * @return AlarmClockDao对象
     */
    public abstract ContentDao contentDao();
    public abstract CommentDao commentDao();
    public abstract ImageDao imageDao();
    public abstract LikeDao likeDao();
    public abstract LinkDao linkDao();
//    public abstract RecordDao getRecordDao();
//    public abstract BaseDao getBaseDao();

    private static volatile AppDatabase INSTANCE;

    public static AppDatabase getDatabase(Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
//                    "alarm_clock" 这个是储存的文件的名字吧 databases里面的
//                    String dbFileName = "login.db";
//                    String  dbFileName="alarm_clock";
                    INSTANCE = Room.databaseBuilder(context, AppDatabase.class, DATABASE_FILENAME)
//                            .allowMainThreadQueries()
//                            .addMigrations(MIGRATION_1_2)
//                    https://blog.csdn.net/u013762572/article/details/106315045
                            .fallbackToDestructiveMigration()
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
